<?php 
## include required files
/*******************************/
require_once '../includefiles.php';
require_once '../model/users.php';
require_once '../model/blogs.php';
require_once '../model/contactus.php';  
require_once '../model/message.php'; 
/*******************************/

## Create Objects
/*******************************/
$userObj = new Model_Users();
$blogObj = new Model_Blogs();
$contctObj =  new Model_Contactus();
$messageObj =  new Model_Message();	
/*******************************/
## fetching last 5 registered user
$userArray=$userObj->getLasrFiveRegistedUser();
$smarty->assign('userArray', $userArray);

## fetching last 5 registered tradesman user
$tradesmanArray=$userObj->getLasrFiveRegisteredTradesman();
$smarty->assign('tradesmanArray',$tradesmanArray);

## fetching last 5 registered homeowner user
$homeownerArray=$userObj->getLasrFiveRegisteredHomeowner();
$smarty->assign('homeownerArray',$homeownerArray);

## fetching last 5 posted jobs 
$postedjobArray = $userObj->getLasrPostedJob();

$contactArray=$contctObj->listRecordWithUnread("",5,0);
$smarty->assign('contactArray',$contactArray);

for($i=0;$i<count($postedjobArray);$i++)
	{
		$getjobtype = $tradeObj->getTradeCategoryDetailsById($postedjobArray[$i]['jobtype_id']);	
		$postedjobArray[$i]['jobtype_name'] = $getjobtype['trade_category'];
	}
	
$smarty->assign('postedjobArray',$postedjobArray);
//echo "<xmp>"; print_r($postedjobArray); echo "</xmp>";

$msgArray = $messageObj->getAllMessage("","","","",5,0);
$i=0;
foreach($msgArray as $msg)
{
	$msgArray[$i]['from_name'] = $userObj->getUserNameByUserId($msg['from_id']);
	$msgArray[$i]['to_name'] = $userObj->getUserNameByUserId($msg['to_id']);
	$i++;
}

$smarty->assign('msgArray',$msgArray);
/*
## fetching last 5 blog
$blogArray=$blogObj->getLasrFiveBlog();
$smarty->assign('blogArray', $blogArray);
*/

## Unset all the objects created which are on this page
//unset($userObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'dashboard/dashboard.tpl');
//unset($smarty);
?>